﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Taxonomy;
using Microsoft.SharePoint;
using MS.InformationManagement.Support.Constants;
using MS.InformationManagement.Support;

namespace MS.InformationManagement.Core.TaxonomyPropertiesDocs
{
    public static class TaxonomyManager
    {

        public static Dictionary<string, string> GetValuesForOneLevelTaxonomyField(string metadataGroupName, string termSet)
        {
            using (SPSite site = new SPSite(SPContext.Current.Site.ID))
            {
                TaxonomySession session = new TaxonomySession(site);
                Group txgroup = session.TermStores[ConfigurationHelper.GetInstance().ConfigItems[GlobalConstants.METADATA_SERVICE_NAME]].Groups[metadataGroupName];
                return (from term in txgroup.TermSets[termSet].Terms.OfType<Term>()
                        select new KeyValuePair<string, string>(term.Id.ToString(), term.Labels[0].Value)).ToDictionary(k => k.Key, k => k.Value);
            }
        }
    }
}
